@extends('admin.layout')
@section('title',$title)
@section('content')
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                用户管理
                <small>在这里，你可以查看管理员信息
                @if(session('info'))
                       <span style="color: red;" class="edit">{{session('info')}}</span>    
                @endif
                </small>
                
            </h1>
            <ol class="breadcrumb">
                <li><a href="{{ url('/admin/user/index')}}"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="{{ url('/admin/user/add')}}">用户管理</a></li>
                <li class="active">用户信息</li>
            </ol>
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">管理员信息详情</h3>
                        </div><!-- /.box-header -->
                        <div class="box-body">

                            <table id="example2" class="table table-bordered table-hover"+>
                                <form action="{{url('/admin/user/index')}}" method="get">
                                <div class="row">
                                    <div class="col-md-2">
                                            <div class="form-group">
                                                <select class="form-control" name="num">
                                                    <option @if(!empty($request['num']) && $request['num']==1) selected="selected" @endif>1</option>
                                                    <option @if(!empty($request['num']) && $request['num']==2) selected="selected" @endif>2</option>
                                                    <option @if(!empty($request['num']) && $request['num']==3) selected="selected" @endif>3</option>
                                                </select>
                                            </div>
                                    </div>
                                    <div class="col-md-4 col-md-offset-6">
                                        <div class="input-group input-group-sm">
                                            <input type="text" class="form-control" name="keywords" value="{{$request['keywords'] or '' }}">
                                            <span class="input-group-btn"><button class="btn btn-info btn-flat" type="submit">Go!</button></span>
                                        </div>
                                        </div>
                                    </div>
                                </form>
                                </div>
                              
                                <thead>
                                <tr>
                                    <th>用户ID</th>
                                    <th>姓名</th>
                                    <th>地址</th>
                                    <th>性别</th>
                                    <th>电话</th>
                                    <th>头像</th>
                                    <th>密码</th>
                                    <th>权限</th>
                                    <th>邮箱</th>
                                    <th>创建时间</th>
                                    <th>操作</th>

                                    
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($data as $row) 
                                <tr>
                                    <td class="uid">{{$row->uid}}</td>
                                    <td>{{$row -> uname}}</td>
                                    <td class="addr">{{$row -> addr}}</td>
                                    <td>
                                    @if($row->sex == 'm')
                                    男
                                    @else
                                    女
                                    @endif
                                    </td>
                                    <td>{{$row -> tel}}</td>
                                    <td><img src="{{asset($row->uface)}}" style="width: 50px;height: 50px;" /></td>
                                    <td>{{Crypt::decryptString($row -> upwd)}}</td>
                                    <td>
                                    @if($row -> auth == 0)
                                    用户
                                    @elseif($row -> auth == 1)
                                    管理员
                                    @else
                                    超级管理员
                                    @endif
                                    </td>
                                    <td>{{$row -> email}}</td>
                                    <td>{{$row -> regtime}}</td>
                                    <td><a href="{{url('/admin/user/delete')}}/{{$row->uid}}">删除</a><a href="{{url('/admin/user/edit')}}/{{$row->uid}}">编辑</a><a href="{{url('/admin/user/change')}}/{{$row->uid}}">修改密码</a></td>
                                </tr>
                                @endforeach
                                </tbody>
                            </table>
                            {{$data -> appends($request) -> links()}}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
     </div><!-- /.content-wrapper -->
     <script>
         window.onload = function()
         {
            var isDBL = true;
            //ajax头信息
            $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });

            $('.addr').on('dblclick',function(){
                if (!isDBL) 
                {
                    return;
                }
                isDBL = false;
                var td = $(this);
                var uid = $(this).parent().find('.uid').html();
                console.log(uid);
                var old_addr = $(this).html();
                var input = $('<input type="text" />');
                input.val(old_addr);
                $(this).html(input);
                $inp = input.select();

                input.on('blur',function(){
                    var new_addr = $(this).val();
                     $.ajax({
                       url:"{{url('/admin/user/changeAddr')}}",
                       type:'GET',
                       data:{uid:uid,addr:new_addr},
                       success:function(data){
                         if (data == '1') 
                         {
                            td.html(new_addr);
                         }else
                         {
                            td.html(old_addr);
                         }
                       },
                       error:function(){

                       },
                       dataType:'TEXT'
                     });
                     isDBL = true;
                });
            });
            $('.edit').fadeOut(2000);
         }
     </script>
@endsection